//
//  UITableView+CellReuse.m
//  魔兽大数据
//
//  Created by 王右 on 2017/11/14.
//  Copyright © 2017年 王右. All rights reserved.
//

#import "UITableView+CellReuse.h"

@implementation UITableView (CellReuse)

- (instancetype)cellWithCellNibName:(NSString *)string
{
    return [self cellWithCellNibName:string identifierName:@""];
}

- (instancetype)cellWithCellNibName:(NSString *)string identifierName:(NSString *)identifierName
{
    if ([identifierName length] == 0) identifierName = string;
    
    id cell = [self dequeueReusableCellWithIdentifier:identifierName];
    if (!cell) {
        NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:string owner:self options:nil];
        if (nibs && nibs.count) {
            cell = [nibs firstObject];
        }
    }
    return cell;
}


- (instancetype)cellWithClassName:(NSString *)string{
    return [self cellWithClassName:string identifierName:@""];
}

- (instancetype)cellWithClassName:(NSString *)string identifierName:(NSString *)identifierName{
    if ([identifierName length] == 0) identifierName = string;
    id cell = [self dequeueReusableCellWithIdentifier:identifierName];
    
    Class cls = NSClassFromString(string);
    if (cls) {
        cell = [[cls alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifierName];
    }
    
    return cell;
}
@end
